package com.example.market.exception;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.example.market.util.JsonResponse;

@ControllerAdvice
@ResponseBody
public class ServiceExceptionHandler {
    @Autowired
    private JsonResponse jsonResult;

    @ExceptionHandler(ServiceException.class)
    public JsonResponse handleException(ServiceException e){
        ExceptionEnum em = e.getExceptionEnum();
        jsonResult.fail(em.getCode() + "", em.getMsg());
        return jsonResult;
    }
}
